package com.tools.db.jdbc;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tools.common.object.Note;

@Note("分页参数抽象类实体")
public abstract class PageModel {

    @Note("当前页码")
    @JsonIgnore
    private Integer currentPage;

    @Note("一页展示条目数")
    @JsonIgnore
    private Integer pageSize;

    public PageModel() {
        this.setCurrentPage(1);
        this.setPageSize(20);
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = (currentPage == null || currentPage < 1) ? 1 : currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = (pageSize == null || pageSize < 0) ? 20 : pageSize;
    }

    @JsonIgnore
    public long getOffset() {
        return (this.currentPage - 1L) * this.pageSize;
    }
}
